package com.qk.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qk.common.PageResult;
import com.qk.entity.Activity;
import com.qk.mapper.ActivityMapper;
import com.qk.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author 28188
 */
@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public PageResult pageActivities(String channel, String type, String status, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<Activity> activities = activityMapper.selectListByCondition(channel, type, status);
        PageInfo pageInfo = new PageInfo<>(activities);
        return new PageResult<>(pageInfo.getTotal(), pageInfo.getList());
    }

    @Override
    public void removeById(Integer id) {
        activityMapper.deleteById(id);
    }

    @Override
    public void saveActivity(Activity activity) {
        activity.setCreateTime(LocalDateTime.now());
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.insertActivity(activity);
    }

    @Override
    public Activity getActivityById(Integer id) {
        return activityMapper.selectById(id);
    }

    @Override
    public void updateActivity(Activity activity) {
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.updateActivity(activity);
    }

    @Override
    public List<Activity> listActivitiesByType(String type) {
        return activityMapper.listActivitiesByType(type);
    }


}
